Skip to main content

How to modify camera resolution by script using Java

How to modify Camera resolution by script using Java


Resolution mode​

In your Java class, do the following:​

public class YourClass extends Component {

// creates 3 new SUIButton
public SUIButton button1, button2, button3; // select in properties

// creates a new Camera
public Camera camera; // select in properties

@Override
public void start() {

}

@Override
public void repeat() {

// checking whether buttons have been pressed
if (button1.isDown()) {

// changing the Camera resolution mode if the conditional is true
camera.setResolutionMode(Camera.ResolutionMode.Percentage);
} else if (button2.isDown()) {

// changing the Camera resolution mode if the conditional is true
camera.setResolutionMode(Camera.ResolutionMode.FixedResolution);
} else if (button3.isDown()) {

// changing the Camera resolution mode if the conditional is true
camera.setResolutionMode(Camera.ResolutionMode.FreeAspectResolution);
}
}
}

Percentage​

In your Java class, do the following:​

public class YourClass extends Component {

// value to control the Camera resolution percentage
public int percentage = 80; // select in properties

// creates a new SUIButton
public SUIButton button; // select in properties

// creates a new Camera
public Camera camera; // select in properties

@Override
public void start() {

}

@Override
public void repeat() {

// checking if the button was pressed
if (button.isDown()) {

// changing the Camera resolution mode if the conditional is true
camera.setResolutionMode(Camera.ResolutionMode.Percentage);
camera.setRenderPercentage(percentage);
}
}
}

FixedResolution​

In your Java class, do the following:​

public class YourClass extends Component {

// value to control the Camera's horizontal resolution pixels
public int widthPixels = 1080; // select in properties

// value to control the Camera's vertical resolution pixels
public int heightPixels = 1920; // select in properties

// creates a new SUIButton
public SUIButton button; // select in properties

// creates a new Camera
public Camera camera; // select in properties

@Override
public void start() {

}

@Override
public void repeat() {

// checking if the button was pressed
if (button.isDown()) {

// changing the Camera resolution mode if the conditional is true
camera.setResolutionMode(Camera.ResolutionMode.FixedPercentage);

// changing the Camera's horizontal resolution pixels if the conditional is true
camera.setFixedResolutionPixelsWidth(widthPixels);

// changing the Camera's vertical resolution pixels if the conditional is true
camera.setFixedResolutionPixelsHeight(heightPixels);
}
}
}

FreeAspectResolution​

In your Java class, do the following:​

public class YourClass extends Component {

// value to control the Camera's horizontal resolution pixels
public int widthPixels = 480; // select in properties

// value to control the Camera's vertical resolution pixels
public int heightPixels = 480; // select in properties

// creates a new SUIButton
public SUIButton button; // select in properties

// creates a new Camera
public Camera camera; // select in properties

@Override
public void start() {

}

@Override
public void repeat() {

// checking if the button was pressed
if (button.isDown()) {

// changing the Camera resolution mode if the conditional is true
camera.setResolutionMode(Camera.ResolutionMode.FreeAspectResolution);

// changing the side type
camera.setFreeAspectResolutionSide(Camera.FreeAspectResolutionSide.Width); // Width or Height

// changing the Camera's horizontal resolution pixels if the conditional is true
camera.setFreeResolutionPixels(widthPixels);

// changing the Camera's vertical resolution pixels if the conditional is true
camera.setFixedResolutionPixelsHeight(heightPixels);
}
}
}